/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-12-25
 * Time: 15:09
 */
public class test3 {
    /*
    LCR 024 反转链表
     */
    public ListNode reverseList(ListNode head) {
        ListNode head2 = new ListNode(0);
        ListNode cur = head;
        while(cur!=null){
            ListNode next = cur.next;
            cur.next = head2.next;
            head2.next = cur;
            cur = next;
        }
        return head2.next;
    }

    private class ListNode {
        int val;
        ListNode next;
        ListNode() {

        }
        ListNode(int val) {
            this.val = val;
        }
        ListNode(int val, ListNode next) {
            this.val = val; this.next = next;
        }
    }
}
